
		set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

alter TRIGGER [ProjectGroupOnUpdate] 
   ON  [dbo].[ProjectGroup] 
   AFTER Update
AS 
	declare @tablePrimaryKey ProjectGroupIDType
	declare @UpdateBy nvarchar(50)
	declare @UpdateIP nvarchar(50)
	declare @UpdateDate datetime
	
	select @tablePrimaryKey = [ProjectGroupID] from inserted
	select @UpdateBy = [UpdateBy] from inserted
	select @UpdateIP = [UpdateIP] from inserted
	select @UpdateDate = [UpdateDate] from inserted
	

if (update([ProjectGroupID]))
 begin
  declare @NewProjectGroupID ProjectGroupIDType
  declare @OldProjectGroupID ProjectGroupIDType

  select @OldProjectGroupID = [ProjectGroupID] from Deleted
  select @NewProjectGroupID = [ProjectGroupID] from inserted
if( @OldProjectGroupID != @NewProjectGroupID)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ProjectGroupID','ProjectGroup',@tablePrimaryKey,@NewProjectGroupID,@OldProjectGroupID,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Description]))
 begin
  declare @NewDescription DescriptionType
  declare @OldDescription DescriptionType

  select @OldDescription = [Description] from Deleted
  select @NewDescription = [Description] from inserted
if( @OldDescription != @NewDescription)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Description','ProjectGroup',@tablePrimaryKey,@NewDescription,@OldDescription,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OfficerName]))
 begin
  declare @NewOfficerName NameType
  declare @OldOfficerName NameType

  select @OldOfficerName = [OfficerName] from Deleted
  select @NewOfficerName = [OfficerName] from inserted
if( @OldOfficerName != @NewOfficerName)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OfficerName','ProjectGroup',@tablePrimaryKey,@NewOfficerName,@OldOfficerName,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OfficerRole]))
 begin
  declare @NewOfficerRole RoleType
  declare @OldOfficerRole RoleType

  select @OldOfficerRole = [OfficerRole] from Deleted
  select @NewOfficerRole = [OfficerRole] from inserted
if( @OldOfficerRole != @NewOfficerRole)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OfficerRole','ProjectGroup',@tablePrimaryKey,@NewOfficerRole,@OldOfficerRole,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Title]))
 begin
  declare @NewTitle TitleType
  declare @OldTitle TitleType

  select @OldTitle = [Title] from Deleted
  select @NewTitle = [Title] from inserted
if( @OldTitle != @NewTitle)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Title','ProjectGroup',@tablePrimaryKey,@NewTitle,@OldTitle,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OfficerEmail]))
 begin
  declare @NewOfficerEmail EmailType
  declare @OldOfficerEmail EmailType

  select @OldOfficerEmail = [OfficerEmail] from Deleted
  select @NewOfficerEmail = [OfficerEmail] from inserted
if( @OldOfficerEmail != @NewOfficerEmail)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OfficerEmail','ProjectGroup',@tablePrimaryKey,@NewOfficerEmail,@OldOfficerEmail,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([OwnerGroupID]))
 begin
  declare @NewOwnerGroupID GroupIDType
  declare @OldOwnerGroupID GroupIDType

  select @OldOwnerGroupID = [OwnerGroupID] from Deleted
  select @NewOwnerGroupID = [OwnerGroupID] from inserted
if( @OldOwnerGroupID != @NewOwnerGroupID)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('OwnerGroupID','ProjectGroup',@tablePrimaryKey,@NewOwnerGroupID,@OldOwnerGroupID,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([FirstFilingDate]))
 begin
  declare @NewFirstFilingDate DateType
  declare @OldFirstFilingDate DateType

  select @OldFirstFilingDate = [FirstFilingDate] from Deleted
  select @NewFirstFilingDate = [FirstFilingDate] from inserted
if( @OldFirstFilingDate != @NewFirstFilingDate)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('FirstFilingDate','ProjectGroup',@tablePrimaryKey,@NewFirstFilingDate,@OldFirstFilingDate,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([PriorityDate]))
 begin
  declare @NewPriorityDate DateType
  declare @OldPriorityDate DateType

  select @OldPriorityDate = [PriorityDate] from Deleted
  select @NewPriorityDate = [PriorityDate] from inserted
if( @OldPriorityDate != @NewPriorityDate)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('PriorityDate','ProjectGroup',@tablePrimaryKey,@NewPriorityDate,@OldPriorityDate,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([ProjectClass]))
 begin
  declare @NewProjectClass ProjectClassType
  declare @OldProjectClass ProjectClassType

  select @OldProjectClass = [ProjectClass] from Deleted
  select @NewProjectClass = [ProjectClass] from inserted
if( @OldProjectClass != @NewProjectClass)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('ProjectClass','ProjectGroup',@tablePrimaryKey,@NewProjectClass,@OldProjectClass,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([PCTCountry]))
 begin
  declare @NewPCTCountry NameType
  declare @OldPCTCountry NameType

  select @OldPCTCountry = [PCTCountry] from Deleted
  select @NewPCTCountry = [PCTCountry] from inserted
if( @OldPCTCountry != @NewPCTCountry)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('PCTCountry','ProjectGroup',@tablePrimaryKey,@NewPCTCountry,@OldPCTCountry,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([PCTPriorityDate]))
 begin
  declare @NewPCTPriorityDate DateType
  declare @OldPCTPriorityDate DateType

  select @OldPCTPriorityDate = [PCTPriorityDate] from Deleted
  select @NewPCTPriorityDate = [PCTPriorityDate] from inserted
if( @OldPCTPriorityDate != @NewPCTPriorityDate)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('PCTPriorityDate','ProjectGroup',@tablePrimaryKey,@NewPCTPriorityDate,@OldPCTPriorityDate,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Applicant]))
 begin
  declare @NewApplicant NameType
  declare @OldApplicant NameType

  select @OldApplicant = [Applicant] from Deleted
  select @NewApplicant = [Applicant] from inserted
if( @OldApplicant != @NewApplicant)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Applicant','ProjectGroup',@tablePrimaryKey,@NewApplicant,@OldApplicant,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Inventor]))
 begin
  declare @NewInventor NameType
  declare @OldInventor NameType

  select @OldInventor = [Inventor] from Deleted
  select @NewInventor = [Inventor] from inserted
if( @OldInventor != @NewInventor)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Inventor','ProjectGroup',@tablePrimaryKey,@NewInventor,@OldInventor,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Type]))
 begin
  declare @NewType CodeTypeType
  declare @OldType CodeTypeType

  select @OldType = [Type] from Deleted
  select @NewType = [Type] from inserted
if( @OldType != @NewType)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Type','ProjectGroup',@tablePrimaryKey,@NewType,@OldType,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([Client]))
 begin
  declare @NewClient CodeTypeType
  declare @OldClient CodeTypeType

  select @OldClient = [Client] from Deleted
  select @NewClient = [Client] from inserted
if( @OldClient != @NewClient)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('Client','ProjectGroup',@tablePrimaryKey,@NewClient,@OldClient,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([TitleSubject]))
 begin
  declare @NewTitleSubject TitleType
  declare @OldTitleSubject TitleType

  select @OldTitleSubject = [TitleSubject] from Deleted
  select @NewTitleSubject = [TitleSubject] from inserted
if( @OldTitleSubject != @NewTitleSubject)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('TitleSubject','ProjectGroup',@tablePrimaryKey,@NewTitleSubject,@OldTitleSubject,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

if (update([IsDelete]))
 begin
  declare @NewIsDelete bit
  declare @OldIsDelete bit

  select @OldIsDelete = [IsDelete] from Deleted
  select @NewIsDelete = [IsDelete] from inserted
if( @OldIsDelete != @NewIsDelete)
begin
	INSERT INTO [dbo].[DBF_UPDATES]
           ([Column],[TableName],[ReferenceID],[NewValue],[OldValue],[UpdateBy],[UpdateIP],[UpdatedTime])
     VALUES
           ('IsDelete','ProjectGroup',@tablePrimaryKey,@NewIsDelete,@OldIsDelete,@UpdateBy,@UpdateIP,@UpdateDate)
end
end

